﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Tencent
{
    class Program
    {
        static void Main(string[] args)
        {
            Test1();
            Console.ReadKey();
        }

        static void Test1()
        {

            string base64Image = TencentOCR.ImageToBase64(@"test_image.png");
            TencentOCR ocr = new TencentOCR("1252867739", "AKIDcAe3HJs1c1FKEwD2LTPDptpaBcs0viqo", "wiIwb9Zs361viNuKgwdu7DC6udkqphZQ");
            GeneralResponse res = ocr.General(base64Image);

            // 将百分比提取出来，得到数组
            string content = "";
            foreach (DataItem item in res.data.items)
            {
                content += item.itemstring;
            }

            string pattern = @"\=\s*(\d+)\s*\%";
            var matches = Regex.Matches(content, pattern);

            List<string> list = new List<string>();
            foreach (Match match in matches)
            {
                list.Add(match.Groups[1].Value);
            }

            string result = string.Join(",", list.ToArray());

            Console.WriteLine();
        }

        static void Test2()
        {
            string temp = "11921177dc27edb93828a8e5ef4774bf034fe7fb";
            string base64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(temp));
        }
    }
}
